package com.zenika.zenbinding.client.renderer;

import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Widget;
import com.zenika.zenbinding.client.ZenBinder;
import com.zenika.zenbinding.client.converter.EnumConverter;
import com.zenika.zenbinding.client.feedback.DummyFeedbackManager;
import com.zenika.zenbinding.client.feedback.FeedbackManager;
import com.zenika.zenbinding.client.handler.ListBindingHandler;
import com.zenika.zenbinding.client.model.BusinessObject;
import com.zenika.zenbinding.client.model.ZenEnum;
import com.zenika.zenbinding.client.model.ListModel;

public class EnumListBoxRenderer implements Renderer {

	private String property;
	private ZenEnum[] choices;
	private String style;
	private FeedbackManager feedback;

	public EnumListBoxRenderer(String property, ZenEnum[] choices) {
		this.property = property;
		this.choices = choices;
	}

	public Widget render(BusinessObject object) {
		ListBox listBox = new ListBox();
		if (this.style != null) {
			listBox.setStyleName(this.style);
		}
		ListBindingHandler handler;
		handler = ZenBinder.createListBindingHandler(listBox, this.choices);
		ZenBinder.bindList(handler, object, this.property, new EnumConverter(this.choices));
		return listBox;
	}

	public Widget render(BusinessObject object, DummyFeedbackManager manager) {
		ListBox listBox = new ListBox();
		if (this.style != null) {
			listBox.setStyleName(this.style);
		}
		ListBindingHandler handler;
		handler = ZenBinder.createListBindingHandler(listBox, this.choices);
		ListModel model = ZenBinder.bindList(handler, object, this.property, new EnumConverter(this.choices));
		if (this.feedback != null) {
			manager.setFeedbackManager(this.feedback);
		}
		model.setFeedbackManager(manager);
		return listBox;
	}

	public void setStyleName(String style) {
		this.style = style;
	}

	public void setFeedbackManager(FeedbackManager feedback) {
		this.feedback = feedback;

	}

}
